﻿using System.Collections.Generic;
using System.Net;

namespace JetBlack.AuthFeedBus.Distributor.Config
{
    /// <summary>
    /// A class representing the configuration of an adapter.
    /// </summary>
    /// <remarks>
    /// For an example of a possible configuration <see cref="ConfigurationSectionHandler"/>.
    /// </remarks>
    public class Distributor
    {
        /// <summary>
        /// The configuration name.
        /// </summary>
        public string Name;

        /// <summary>
        /// The port to connect to.
        /// </summary>
        public int Port;

        /// <summary>
        /// The roles distributor clients may assume.
        /// </summary>
        public readonly ClientRole Allow;

        /// <summary>
        /// The roles distributor client may not assume.
        /// </summary>
        public readonly ClientRole Deny;

        /// <summary>
        /// The feed configurations.
        /// </summary>
        public readonly IDictionary<string, FeedConfiguration> FeedConfigurations;

        /// <summary>
        /// Construct an adapter configuration object.
        /// </summary>
        /// <param name="name">The configuration name.</param>
        /// <param name="port">The configuration port.</param>
        /// <param name="allow">Allowed roles.</param>
        /// <param name="deny">Denied roles.</param>
        /// <param name="feedConfigurations">The feed configurations.</param>
        public Distributor(string name, int port, ClientRole allow, ClientRole deny, IList<FeedConfiguration> feedConfigurations)
        {
            Name = name;
            Port = port;
            Allow = allow;
            Deny = deny;
            FeedConfigurations = new Dictionary<string, FeedConfiguration>();
            foreach (var feedConfiguration in feedConfigurations)
                FeedConfigurations.Add(feedConfiguration.Feed, feedConfiguration);
        }
    }
}
